#encode=utf8
from create_corpus import MyGensim

class MyLSI():
    def __init__(self):
        self.mygensim = MyGensim()
        self.lda_model = self.mygensim.get_ldamodel()
        
    def training(self):
        lsi = self.mygensim.get_lsimodel()
        self.mygensim.save_ldi_model(lsi)

    def get_lda_topics_num(self):
        return self.lda_model.num_topics

    def print_lda_topics(self):
        return self.lda_model.print_topics(self.get_lda_topics_num())

    def print_to_file(self, path='./print_model.lda'):
        f = open(path, "w")
        lda_str = self.print_lda_topics()
        topic_no = 0
        for i in lda_str:
            f.write("Topic #%d: " %topic_no + i.encode("utf-8") + '\n')
            topic_no += 1
        f.close()
        
    def print_to_database(self):
        lda_topics_DB = LDATopicsDB()
        topic_no = 0
        for i in self.print_lda_topics():
            lda_topics_DB.insert(topic_no, "Topic #%d: " %topic_no + i.encode("utf-8") + '\n')
            topic_no += 1

if __name__ == "__main__":
    mylsi = MyLSI()
    mylsi.training()

